{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c96199b9-9271-4d0c-959d-5a92f2812ce4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<__main__.Student object at 0x00000245470F2460>\n"
     ]
    }
   ],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "\n",
    "print(Student('Thomas'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "081168e6-5704-45d1-9cc7-899664a1d8b0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Student object: Thomas \n"
     ]
    }
   ],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "\n",
    "    def __str__(self):\n",
    "        return 'Student object: %s ' % self.name\n",
    "\n",
    "print(Student('Thomas'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0e0807d0-9a29-4fb4-9678-e113d3cdfb43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<__main__.Student at 0x245475f0ee0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Student('Tom')\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "eb285c00-eae7-4019-9be9-5a18fffab616",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Student object: Tom "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Student(object):\n",
    "    def __init__(self, name):\n",
    "        self.name = name\n",
    "\n",
    "    def __str__(self):\n",
    "        return 'Student object: %s ' % self.name\n",
    "    __repr__ = __str__\n",
    "s = Student('Tom')\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3c62fd8d-50b6-4a02-a98d-8a7a4b9e5fda",
   "metadata": {},
   "outputs": [],
   "source": [
    "class fib(object):\n",
    "    def __init__(self): \n",
    "        self.b = 0 \n",
    "\n",
    "    def __iter__(self):\n",
    "        return  self\n",
    "\n",
    "    def __next__(self): \n",
    "        self.b = self.b + 1\n",
    "        if self.b > 10:\n",
    "            raise StopIteration()\n",
    "        return self.b \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "881d6ba9-5d4f-4a46-a77b-0e831ac88c44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "for n in fib():\n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f40d4b4f-c914-43e8-9983-935668bbd838",
   "metadata": {},
   "outputs": [],
   "source": [
    "class iterRange(object):\n",
    "    def __getitem__(self,n):\n",
    "        b = 1\n",
    "        for x in range(n):\n",
    "             b = b + 1\n",
    "        return b \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1eefcd32-9d6f-4f8b-aba6-c13c24df5874",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f = iterRange() \n",
    "f[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1dbe9031-06d3-4cc6-959c-7fb2d6e11e28",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "84a6deec-08fa-45ef-8ec5-550b5282c270",
   "metadata": {},
   "outputs": [],
   "source": [
    "class iterRange(object):\n",
    "    def __getitem__(self,n):\n",
    "        if isinstance(n ,int):\n",
    "            b = 1\n",
    "            for x in range(n):\n",
    "                 b = b + 1\n",
    "            return b\n",
    "        if isinstance(n, slice): \n",
    "            start = n.start\n",
    "            stop = n.stop\n",
    "            if start is None:\n",
    "                start = 0\n",
    "            b = 1\n",
    "            L = []\n",
    "            for x in range(stop):\n",
    "                if x >= start:\n",
    "                    L.append(b)\n",
    "                    b = b+1 \n",
    "            return L "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e54c7be0-0c2b-44d1-8a11-31f63f665023",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f = iterRange()\n",
    "f[0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "2f1fc7e0-09b4-4419-a523-605b91199e9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "486114ee-6928-45c4-9c8f-b28db83ff876",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Chain(object):\n",
    "    def __init__(self, path=''):\n",
    "        self._path = path\n",
    "        print(\"init _path: %s\" % self._path)\n",
    "\n",
    "    def __getattr__(self, path):\n",
    "        return Chain(' self:%s get:/%s' % (self._path, path))\n",
    "\n",
    "    def __str__(self):\n",
    "        return self._path\n",
    "\n",
    "    __repr__ = __str__\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "b659dfd6-fcbd-4336-883c-0563ae58b033",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "init _path: \n",
      "init _path:  self: get:/status\n",
      "init _path:  self: self: get:/status get:/user\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n",
      "init _path:  self: self: self: get:/status get:/user get:/_ipython_canary_method_should_not_exist_\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       " self: self: get:/status get:/user"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Chain().status.user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7faf1cc3-44eb-402b-a654-b37751ff972e",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student(object):\n",
    "    def __init__(self,name):\n",
    "        self.name = name\n",
    "        \n",
    "    def __call__(self):\n",
    "        print('My name is %s' % self.name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8664a161-23af-4451-b101-351edd8a2c24",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My name is Thomas\n"
     ]
    }
   ],
   "source": [
    "s = Student('Thomas')\n",
    "s()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "36a7cdbb-ff74-4180-a768-706a88e6221e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "callable(max)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "22ae0423-c913-4091-95e5-fd755cc320b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "callable(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ee44839a-3765-4dc4-842b-eb6f08fced0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "callable( Student('t'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2098a3a-1c94-4f7f-b44a-5e50cda3325e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
